home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / scsh-0.4 / scsh-0 / scsh-0.4.2 / scsh / bsd / waitcodes.scm < prev   
Text File  |  1995-11-04  |  1KB  |  41 lines

  1. ;;; Scsh routines for analysing exit codes returned by WAIT.
  2. ;;; Copyright (c) 1994 by Olin Shivers.
  3. ;;;
  4. ;;; To port these to a new OS, consult /usr/include/sys/wait.h, 
  5. ;;; and check the WIFEXITED, WEXITSTATUS, WIFSTOPPED, WSTOPSIG, 
  6. ;;; WIFSIGNALED, and WTERMSIG macros for the magic fields they use.
  7. ;;; These definitions are for BSD4.4-Lite.
  8. ;;;
  9. ;;; I could have done a portable version by making C calls for this,
  10. ;;; but it's such overkill.
  11.  
  12.  
  13. ;;; If process terminated normally, return the exit code, otw #f.
  14.  
  15. (define (status:exit-val status)
  16.   (and (zero? (bitwise-and #x7F status))
  17.        (arithmetic-shift status -8)))
  18.  
  19.  
  20.  
  21. ;;; If the process was suspended, return the suspending signal, otw #f.
  22.  
  23. (define (status:stop-sig status)
  24.   (and (= #x7F (bitwise-and status #x7F))
  25.        (arithmetic-shift status -8)))
  26.  
  27.  
  28. ;;; If the process terminated abnormally, 
  29. ;;; return the terminating signal, otw #f.
  30.  
  31. (define (status:term-sig status)
  32.   (let ((termsig (bitwise-and status #x7F)))
  33.     (and (not (zero? termsig))                ; Didn't exit.
  34.      (not (= #x7F))                    ; Not suspended.
  35.      termsig)))
  36.  
  37.  
  38. ;;; Flags.
  39. (define wait/poll         1)    ; Don't hang if nothing to wait for.
  40. (define wait/stopped-children    2)    ; Report on suspended subprocs, too.
  41.